﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Campus.Main.Basic.InsertValues;
using cpmntctrl;
using dbcntn;

namespace Campus.Main.Basic.Settings
{
    public sealed partial class BedForm : DefaultForm
    {
        public BedForm()
        {
            InitializeComponent();
            aToDb=new ConnectionToDb(Helper.ConnectionString);
            Initialize();
        }
        public override void Initialize()
        {
            aToDb.AddItemDBGridView(dataGridView1,Query.Bed);
            aToDb.AddItem(comboBox1,"yurtdef");
            comboBox3.SelectedIndex = 0;
            //aToDb.AddItem(comboBox2,"room");
            ControlComponent.UnVisibleCells(dataGridView1,0,1,2);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (comboBox2.SelectedValue!=null)
            {
                int a = Convert.ToInt32(comboBox2.SelectedValue);
                int temp = Convert.ToInt32(comboBox3.SelectedItem);
                aToDb.InsertIntoTable("bed","room_id","description",a,temp);
                //aToDb.InsertIntoTable("bed","room_id","bed_id",Convert.ToInt32(comboBox2.SelectedValue),Convert.ToInt32(comboBox3.SelectedValue));
                Initialize();
            }
            else
            {
                MessageBox.Show("Талланы толткргула!!!");
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex==-1|| e.RowIndex==-1)
            {
                return;
            }
            List<string> data=new List<string>();
            ControlComponent.AddToList(data,dataGridView1,e,0,1,2,5);
            Bed f=new Bed(data);
            f.FormClosed += Bind;
            f.ShowDialog();
        }

        private void BedForm_Load(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
        {
            Type t = typeof (Int32);
            if (comboBox1.SelectedValue.GetType()==t)
            {
                int a = Convert.ToInt32(comboBox1.SelectedValue);
                aToDb.AddItem(comboBox2,"room","yurt_id",a);
                
                if (comboBox2.SelectedValue==null)
                {
                    comboBox3.DataSource = null;
                }
            }
        }

        private void comboBox2_SelectedValueChanged(object sender, EventArgs e)
        {
            Type t = typeof (Int32);
            if (comboBox2.SelectedValue.GetType() == t)
            {
                int a = Convert.ToInt32(comboBox2.SelectedValue);
                //aToDb.AddItem(comboBox3,"bed","room_id",a);
            }
        }
    }
}
 